package com.ruoyi.sys.garden.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.sys.garden.entity.TbServiceHotline;
import com.ruoyi.sys.garden.service.ITbServiceHotlineService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 服务热线Controller
 * 
 * @author jinsuo
 * @date 2022-05-24
 */
@RestController
@RequestMapping("/system/hotline")
public class TbServiceHotlineController extends BaseController
{
    @Autowired
    private ITbServiceHotlineService tbServiceHotlineService;

    /**
     * 查询服务热线列表
     */
    @PreAuthorize("@ss.hasPermi('system:hotline:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbServiceHotline tbServiceHotline)
    {
        startPage();
        List<TbServiceHotline> list = tbServiceHotlineService.selectTbServiceHotlineList(tbServiceHotline);
        return getDataTable(list);
    }

    /**
     * 导出服务热线列表
     */
    @PreAuthorize("@ss.hasPermi('system:hotline:export')")
    @Log(title = "服务热线", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbServiceHotline tbServiceHotline)
    {
        List<TbServiceHotline> list = tbServiceHotlineService.selectTbServiceHotlineList(tbServiceHotline);
        ExcelUtil<TbServiceHotline> util = new ExcelUtil<TbServiceHotline>(TbServiceHotline.class);
        util.exportExcel(response, list, "服务热线数据");
    }

    /**
     * 获取服务热线详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:hotline:query')")
    @GetMapping(value = "/{shId}")
    public AjaxResult getInfo(@PathVariable("shId") Long shId)
    {
        return AjaxResult.success(tbServiceHotlineService.selectTbServiceHotlineByShId(shId));
    }

    /**
     * 新增服务热线
     */
    @PreAuthorize("@ss.hasPermi('system:hotline:add')")
    @Log(title = "服务热线", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbServiceHotline tbServiceHotline)
    {
        return toAjax(tbServiceHotlineService.insertTbServiceHotline(tbServiceHotline));
    }

    /**
     * 修改服务热线
     */
    @PreAuthorize("@ss.hasPermi('system:hotline:edit')")
    @Log(title = "服务热线", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbServiceHotline tbServiceHotline)
    {
        return toAjax(tbServiceHotlineService.updateTbServiceHotline(tbServiceHotline));
    }

    /**
     * 删除服务热线
     */
    @PreAuthorize("@ss.hasPermi('system:hotline:remove')")
    @Log(title = "服务热线", businessType = BusinessType.DELETE)
	@DeleteMapping("/{shIds}")
    public AjaxResult remove(@PathVariable Long[] shIds)
    {
        return toAjax(tbServiceHotlineService.deleteTbServiceHotlineByShIds(shIds));
    }
}
